// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   check_ok.java

package hr.salary_standard;

import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;
import validata.ValidataTag;

public class check_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;

	public check_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			PrintWriter out = response.getWriter();
			nseer_db_backup1 hr_db = new nseer_db_backup1(dbApplication);
			ValidataTag vt = new ValidataTag();
			ValidataNumber validata = new ValidataNumber();
			if (hr_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String standard_ID = request.getParameter("standard_ID");
				String config_id = request.getParameter("config_id");
				String sql6 = (new StringBuilder("select id from hr_workflow where object_ID='")).append(standard_ID).append("' and type_id='02' and ((check_tag='0' and config_id<'").append(config_id).append("') or (check_tag='1' and config_id='").append(config_id).append("'))").toString();
				ResultSet rs6 = hr_db.executeQuery(sql6);
				if (!rs6.next())
				{
					String standard_name = request.getParameter("standard_name");
					String major_type = request.getParameter("major_type");
					String designer = request.getParameter("designer");
					String item_name[] = request.getParameterValues("item_name");
					String salary[] = request.getParameterValues("salary");
					String details_number[] = request.getParameterValues("details_number");
					String checker = request.getParameter("checker");
					String checker_ID = request.getParameter("checker_ID");
					String check_time = request.getParameter("check_time");
					String bodyb = new String(request.getParameter("remark").getBytes("UTF-8"), "UTF-8");
					String remark = exchange.toHtml(bodyb);
					if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "hr_salary_standard", "standard_ID", standard_ID, "check_tag").equals("0"))
					{
						int p = 0;
						for (int i = 0; i < item_name.length; i++)
							if (!salary[i].equals(""))
							{
								StringTokenizer tokenTO4 = new StringTokenizer(salary[i], ",");
								String salary1;
								for (salary1 = ""; tokenTO4.hasMoreTokens(); salary1 = (new StringBuilder(String.valueOf(salary1))).append(tokenTO4.nextToken()).toString());
								if (!validata.validata(salary1))
									p++;
							}

						if (p == 0)
						{
							int n = 0;
							double salary_sum = 0.0D;
							for (int i = 0; i < item_name.length; i++)
								if (!salary[i].equals(""))
								{
									StringTokenizer tokenTO4 = new StringTokenizer(salary[i], ",");
									String salary1 = "";
									while (tokenTO4.hasMoreTokens()) 
									{
										salary1 = (new StringBuilder(String.valueOf(salary1))).append(tokenTO4.nextToken()).toString();
										if (salary1.indexOf("-") != -1)
											n++;
									}
								}

							if (n == 0)
							{
								try
								{
									for (int i = 0; i < item_name.length; i++)
									{
										if (salary[i].equals(""))
											salary[i] = "0";
										String salarying = "";
										for (StringTokenizer tokenTO = new StringTokenizer(salary[i], ","); tokenTO.hasMoreTokens();)
											salarying = (new StringBuilder(String.valueOf(salarying))).append(tokenTO.nextToken()).toString();

										salary_sum += Double.parseDouble(salarying);
										String sql4 = (new StringBuilder("update hr_salary_standard_details set standard_name='")).append(standard_name).append("',salary='").append(salarying).append("' where standard_ID='").append(standard_ID).append("' and details_number='").append(details_number[i]).append("'").toString();
										hr_db.executeUpdate(sql4);
									}

									String sql2 = (new StringBuilder("update hr_salary_standard set standard_name='")).append(standard_name).append("',major_type='").append(major_type).append("',designer='").append(designer).append("',checker='").append(checker).append("',check_time='").append(check_time).append("',salary_sum='").append(salary_sum).append("',remark='").append(remark).append("' where standard_ID='").append(standard_ID).append("'").toString();
									hr_db.executeUpdate(sql2);
									String sql = (new StringBuilder("update hr_workflow set checker='")).append(checker).append("',checker_ID='").append(checker_ID).append("',check_time='").append(check_time).append("',check_tag='1' where object_ID='").append(standard_ID).append("' and config_id='").append(config_id).append("' and type_id='02'").toString();
									hr_db.executeUpdate(sql);
									sql = (new StringBuilder("select id from hr_workflow where object_ID='")).append(standard_ID).append("' and check_tag='0' and type_id='02'").toString();
									ResultSet rset = hr_db.executeQuery(sql);
									if (!rset.next())
									{
										sql = (new StringBuilder("update hr_salary_standard set check_tag='1' where standard_ID='")).append(standard_ID).append("'").toString();
										hr_db.executeUpdate(sql);
										sql = (new StringBuilder("update hr_file set salary_standard_name='")).append(standard_name).append("',major_type='").append(major_type).append("',salary_sum='").append(salary_sum).append("' where salary_standard_ID='").append(standard_ID).append("'").toString();
										hr_db.executeUpdate(sql);
									}
								}
								catch (Exception ex)
								{
									out.println((new StringBuilder("error")).append(ex).toString());
								}
								response.sendRedirect("hr/salary_standard/check_ok_a.jsp");
							} else
							{
								response.sendRedirect((new StringBuilder("hr/salary_standard/check_ok_b.jsp?standard_ID=")).append(standard_ID).toString());
							}
						} else
						{
							response.sendRedirect((new StringBuilder("hr/salary_standard/check_ok_c.jsp?standard_ID=")).append(standard_ID).toString());
						}
					} else
					{
						response.sendRedirect("hr/salary_standard/check_ok_d.jsp");
					}
				} else
				{
					response.sendRedirect("hr/file/check_ok.jsp?finished_tag=0");
				}
				hr_db.commit();
				hr_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception exception) { }
	}
}
